<? 
ob_start();
session_start();
$sess_id=$_SESSION['sess_id'];
$sess_user=$_SESSION['sess_user'];
$sess_status=$_SESSION['sess_status'];
$flag = $_SESSION['sess_flag'];
if ($sess_id<>session_id() || $sess_user=="" || $sess_status<>"active") {
	$_SESSION['cur_page'] = "admin/index.php?module=sender";
	header( "Location: ../login.php");exit();
}
?>
<form name="sender" method="post" action="">
<?php
include('../config.inc.php');
echo "<meta http-equiv='content-type' content='text/html; charset=$charset'>"; 
	$sql = "select * 
			from fault_type fa
			left join send se on fa.id = se.Fault_Type ";
	$result = mysql_query($sql);
	$num = mysql_num_rows($result);
	while($arr = mysql_fetch_array($result)){
	echo "<input name='ftype' type='text' id='ftype' value='".$arr['id'].". ".$arr['fault_name']."' disabled>
  <input name='sender".$arr['id']."' type='text' id='sender".$arr['id']."' value='".$arr['Email']."' onClick=\"window.open('popup.php?input=sender".$arr['id']."','_blank','width=650px,height=400px,scrollbars=yes')\">
  <input type='button' name='Submit' value='update' onClick=\"javascript:Sender($arr[id],document.sender.sender$arr[id].value,'updatesend');this.disabled=true;\"><br>";
	}
	$sql .= " order by se.Fault_Type desc";
	$ft = mysql_fetch_array(mysql_query($sql));
	$Fault = $ft[Fault_Type];
	$Fault_name = $ft[fault_name];
?>
<p><small>ผลการทำงาน : </small></p>
<div id='updatesend'></div>
<p><!--<a href="javascript:genformadd();">เพิ่มผู้รับ</a>--></p>
</form>

<script language='javascript' src='../js/script.js'></script>
<script language="javascript">
function Sender(type,sender,page){
	//alert(type);
	//alert(sender);
	//alert(page);
	var url = 'updatesql.php';
	var pmeters = "type="+type+"&sender="+sender+"&page="+page;
	var xmlHttp = Inint_AJAX();
	
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 3){ document.getElementById("updatesend").innerHTML = "Loading...";}
		if(xmlHttp.readyState == 4){ 
			document.getElementById("updatesend").innerHTML = xmlHttp.responseText;
			}
	};
	xmlHttp.open('POST',url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(pmeters);

}
function genformadd(){
	var Fault_Type = "<?=$Fault;?>";
	var Fault_name = "<?=$Fault_name;?>";
	var Fault_Type = ++Fault_Type;
	document.getElementById("formadd").innerHTML = "<input name='fault_id' type='text' id='fault_id' value='"+Fault_Type+". '> <input name='newsender' type='text' id='newsender' onClick=\"window.open('popup.php?input=newsender','_blank','width=650px,height=400px,scrollbars=yes,toolbar=1,nemubar=1,location=1')\"> <input type='submit' name='Submit' value='Submit'>";
}
</script>